package com.dongdongsongcan.app.activity;

import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ViewFlipper;

import com.dongdongsongcan.app.R;
import com.dongdongsongcan.app.control.bean.ShopData;
import com.dongdongsongcan.app.fragment.ShopDetailFoodlistFragment;
import com.dongdongsongcan.app.fragment.ShopDetailIntroFragment;
import com.su.dolphin.utils.mgr.DpActivityManager;
import com.su.dolphin.utils.mgr.DpFragmentManager;
import com.su.dolphin.utils.ui.TipsUtil;
import com.su.dolphin.view.activity.BaseActivity;

public class ShopDetailActivity extends BaseActivity {

    private ViewFlipper mShopdetail_tab_container;
    private View mShopdetail_tab1, mShopdetail_tab2;
    private ShopData.Shop mShop;

    public static void startFrom(Context context, ShopData.Shop shop) {
        Bundle bundle = new Bundle();
        bundle.putSerializable("shop", shop);
        DpActivityManager.i().startActivity(context, ShopDetailActivity.class,
                bundle);
    }

    public ShopData.Shop getShop() {
        return mShop;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getIntent().getExtras() != null) {
            mShop = (ShopData.Shop) getIntent().getExtras().getSerializable("shop");
        }
        if (mShop == null) {
            TipsUtil.toast("没有店铺信息!");
            return;
        }
        setContentView(R.layout.activity_shop_detail);
        setTitle(mShop.getShop_name() + "店铺详情");
    }

    @Override
    public void initView() {
        DpFragmentManager.i().replaceFragment(this, R.id.shopdetail_foodlist,
                ShopDetailFoodlistFragment.class);
        DpFragmentManager.i().replaceFragment(this, R.id.shopdetail_intro,
                ShopDetailIntroFragment.class);

        mShopdetail_tab_container = (ViewFlipper) findViewById(R.id.shopdetail_tab_container);
        mShopdetail_tab1 = findViewById(R.id.shopdetail_tab1);
        mShopdetail_tab2 = findViewById(R.id.shopdetail_tab2);

    }

    @Override
    public void setListener() {
        mShopdetail_tab1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                mShopdetail_tab_container.setDisplayedChild(0);
            }
        });
        mShopdetail_tab2.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                mShopdetail_tab_container.setDisplayedChild(1);

            }
        });
    }

    @Override
    public void initData() {

    }

    @Override
    public void onBackPressed() {
        android.support.v4.app.Fragment fragment = DpFragmentManager.i().findFragmentByTag(this, ShopDetailFoodlistFragment.class);
        if (fragment instanceof ShopDetailFoodlistFragment) {
            ShopDetailFoodlistFragment shopDetailFoodlistFragment = (ShopDetailFoodlistFragment) fragment;
            if (shopDetailFoodlistFragment.onBackPressed()) {
                return;
            }
        }
        super.onBackPressed();

    }
}
